package com.changgou.goods.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.HashSet;

/**
 * 开启swagger2
 */
@Configuration
@EnableSwagger2
public class SwaggerConfiguration {

 @Bean
 public Docket createRestApi() {
     HashSet<String> strings = new HashSet<>();
     //设置返回的值是JSON格式
     strings.add("application/json");
     return new Docket(DocumentationType.SWAGGER_2)
     .apiInfo(apiInfo())
     .produces(strings)
     .groupName("goods-group")//商品组
     .select()
             //扫描扫描包路径 controller所在的
     .apis(RequestHandlerSelectors.basePackage("com.changgou.goods"))
     .paths(PathSelectors.any())
     .build();
 }

 private ApiInfo apiInfo() {
     return new ApiInfoBuilder()
             //设置标题
     .title("" +
             "服务后台RESTful APIs接口文档")

     .description("服务swagger-bootstrap-ui在线接口文档")
             //访问地址
     .termsOfServiceUrl("http://localhost:8999/")
             //联系人
     .contact("ljh@itcast.cn")
             //版本
     .version("1.0")
             //构建
     .build();
 }
}